package educrypt.analysis;

import java.util.Comparator;

public class FrequencyPairByPercentage implements Comparator<FrequencyPair> {

	@Override
	public int compare(FrequencyPair o1, FrequencyPair o2) {
		int res = 0;
		// Same percentage -> alphabetic order
		if (((Double) o1.getPercentage()).equals(o2.getPercentage())) {
			res = o1.getSymbols().compareTo(o2.getSymbols());
		} else { // By default -> Order by percentage
			res = ((Double) o1.getPercentage()).compareTo(o2.getPercentage());
		}
		return res;
	}
}